package com.dongline.test.project1;

import com.dongline.test.huizongliuliang.FlowDriver;
import com.dongline.test.huizongliuliang.FlowMapper;
import com.dongline.test.huizongliuliang.FlowReducer;
import com.dongline.test.huizongliuliang.FlowWritable;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.NullWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Job;
import org.apache.hadoop.mapreduce.Mapper;
import org.apache.hadoop.mapreduce.lib.input.FileInputFormat;
import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat;

import java.io.IOException;

public class MyMapper extends Mapper<LongWritable, Text,Text, NullWritable> {


    Text text=new Text();
    @Override
    protected void map(LongWritable key, Text value, Context context) throws IOException, InterruptedException {
        String line=value.toString();
        String [] strs=line.split(" ");
        if(strs[3].equals("c.r.w.LogCostFilter")&&strs[7].split(".").length==1)
        {

            text.set(strs[0]+" "+strs[7]);
            context.write(text,NullWritable.get());
        }

    }

    public static void main(String[] args) throws IOException, ClassNotFoundException, InterruptedException {

        Configuration configuration = new Configuration();


        Job job=Job.getInstance(configuration);

        ///这句话很重要必须加上
        job.setJarByClass(MyMapper.class);


        job.setMapperClass(MyMapper.class);
//        job.setReducerClass(FlowReducer.class);

        job.setNumReduceTasks(0);
//
//        job.setMapOutputKeyClass(Text.class);
//        job.setMapOutputValueClass(FlowWritable.class);



        job.setOutputKeyClass(Text.class);
        job.setOutputValueClass(NullWritable.class);

        FileInputFormat.setInputPaths(job,new Path(args[0]));
        FileOutputFormat.setOutputPath(job,new Path(args[1]));



//        job.setCombinerClass();可以设置一个Combiner，功能类似于reducer，但是是运行在maptask上的。maptask自己数据进行分区排序之前调用一次。分区排序后调用一次。业务场景



        boolean re= job.waitForCompletion(true);

        System.exit(re?0:1);
    }

}
